#!/bin/bash

# 安卓UI预览工具启动脚本

echo "================================================"
echo "安卓UI预览工具 - Android UI Explorer"
echo "================================================"
echo

# 检查Python环境
echo "正在检查Python环境..."
if ! command -v python3 &> /dev/null; then
    echo "错误: 未找到Python3，请先安装Python 3.7+"
    echo "Ubuntu/Debian: sudo apt-get install python3 python3-pip"
    echo "CentOS/RHEL: sudo yum install python3 python3-pip"
    echo "macOS: brew install python3"
    exit 1
fi

# 检查Python版本
python_version=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
required_version="3.7"

if [ "$(printf '%s\n' "$required_version" "$python_version" | sort -V | head -n1)" != "$required_version" ]; then
    echo "错误: 需要Python 3.7或更高版本"
    echo "当前版本: $python_version"
    exit 1
fi

echo "✓ Python版本: $python_version"

# 检查依赖包
echo "正在检查依赖包..."
if ! python3 -c "import tkinter, PIL" &> /dev/null; then
    echo "正在安装依赖包..."
    if ! pip3 install -r requirements.txt; then
        echo "错误: 依赖包安装失败"
        exit 1
    fi
fi

echo "✓ 依赖包检查完成"

# 检查ADB工具
echo "正在检查ADB工具..."
if ! command -v adb &> /dev/null; then
    echo "警告: 未找到ADB工具"
    echo "请确保ADB已安装并添加到系统PATH中"
    echo "Ubuntu/Debian: sudo apt-get install android-tools-adb"
    echo "CentOS/RHEL: sudo yum install android-tools"
    echo "macOS: brew install android-platform-tools"
    echo
else
    echo "✓ ADB工具可用"
fi

# 创建必要目录
echo "正在创建必要目录..."
mkdir -p exports logs screenshots
echo "✓ 目录创建完成"

echo "启动应用..."
echo "================================================"

# 启动应用
python3 run.py 